下图是winMutexAlloc 分配的互斥锁类型有8种,目前使用了6种
** <li> SQLITE_MUTEX_FAST 0
** <li> SQLITE_MUTEX_RECURSIVE 1
//1 2基本没区别 创建互斥体时使用
** <li> SQLITE_MUTEX_STATIC_MASTER 2
** <li> SQLITE_MUTEX_STATIC_MEM 3
** <li> SQLITE_MUTEX_STATIC_MEM2 4 //NOT USED
** <li> SQLITE_MUTEX_STATIC_PRNG 5
** <li> SQLITE_MUTEX_STATIC_LRU 6
** <li> SQLITE_MUTEX_STATIC_PMEM 7
//除了1 2 其他需要指向已经分配了的互斥体,目前只使用了6种
静态互斥体只供SQLite 内部用,用户调用时使用的是SQLITE_MUTEX_FAST 或者SQLITE_MUTEX_RECURSIVE返回的动态互斥体,只有当使用静态互斥体时,sqlite3_mutex_alloc()才返回相同类型,动态互斥体如果存在,类型会变化。
static sqlite3_mutex *winMutexAlloc(int iType){
sqlite3_mutex *p;
switch( iType ){
case SQLITE_MUTEX_FAST:
case SQLITE_MUTEX_RECURSIVE: {
p = sqlite3MallocZero( sizeof(*p) );//最终调用memset分配空间
if( p ){
#ifdef SQLITE_DEBUG
p->id = iType;
#endif
#if SQLITE_OS_WINRT
InitializeCriticalSectionEx(&p->mutex, 0, 0);
#else
InitializeCriticalSection(&p->mutex);
#endif
}
break;
}
default: {
assert( winMutex_isInit==1 );
assert( iType-2 >= 0 );
assert( iType-2 < ArraySize(winMutex_staticMutexes) );
p = &winMutex_staticMutexes[iType-2];
#ifdef SQLITE_DEBUG
p->id = iType;
#endif
break;
}
}
return p;
}